package com.fhz.a2102shopjava.ui.login.data;

import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LiveData;

import com.fhz.a2102shopjava.anno.LiveDataCallAdapterFengService;
import com.fhz.a2102shopjava.anno.OKHttpCallAdapterFengService;
import com.fhz.a2102shopjava.api.FengService;
import com.fhz.a2102shopjava.api.OkHttpCallAdapterFengServiceApi;
import com.fhz.a2102shopjava.callback.ApiResponse;
import com.fhz.a2102shopjava.entity.ResponseBean;
import com.fhz.a2102shopjava.ui.login.data.model.LoggedInUser;

import java.io.IOException;

import javax.inject.Inject;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.http.Body;

/**
 * Class that handles authentication w/ login credentials and retrieves user information.
 */
public class LoginDataSource  {

    @Inject
    @LiveDataCallAdapterFengService
    public FengService mFengService;


    @Inject
    public LoginDataSource() {
    }

    private LoggedInUser mLoggedInUser;

    public LiveData<ApiResponse<LoggedInUser>> login(String username, String password) {

//        try {
            return mFengService.login(username, password);
//        } catch (Exception e) {
//            return new Result.Error(new IOException("Error logging in", e));
//        }
//        System.out.println("没劲");
//        return new Result.Success<>(mLoggedInUser);

    }

    public LiveData<ApiResponse<LoggedInUser>> register(LoggedInUser hUser){
        return mFengService.register(hUser);
    }

    public void logout() {
        // TODO: revoke authentication
    }
}